const TOAST_CLASS = 'toast'
const TOAST_OUT_CLASS = 'toast out'
let innerHtml = ""
function toast(msg,div, time = 1500) {
    let body = document.querySelector('#'+div);
    if (body.querySelector('.toast')) {
        body.removeChild(body.querySelector('.toast'))
    }
    let toastElem = document.createElement('div')
    toastElem.setAttribute('class', TOAST_CLASS)
    innerHtml = `<sapn>${msg}</sapn>`
    toastElem.innerHTML = innerHtml;
    body.appendChild(toastElem);
    setTimeout(function () {
        toastElem.setAttribute('class', TOAST_OUT_CLASS)
    }, time)
    setTimeout(function () {
        let elm = body.querySelector('.toast');
        if (elm) {
            body.removeChild(elm)
        }
    }, time + 500)

}
export default toast